/**
 * 全局模板需要调用的方法
 *
 * @author Ljb
 * @date 2018/3/6
 * @copyright Created by Panxsoft.
 */
new Vue ({
    data: function () {
        return {
            keyword : '',       //搜索关键词
            show_btn : false,   //搜索区域的显隐
            dropDown: false, // 下拉的状态
            currentUrl:'/',
        }
    },

    computed:{
        /**
         * 判断是否为首页
         */
        isHome: function (){
           if ( RegExp('/seo/').test(location.pathname) ) return false;
           return !/^\/(production|case|video|project-case|solution-case|news|about)(\/#)?/.test(location.pathname);
        }
    },

    methods: {

        /**
         *  设置下拉的状态为真，打开
         */
        open: function () {
            this.dropDown =  true;
        },
        
        /**
         *  设置下拉的状态为false，关闭
         */
        close: function () {
            this.dropDown =  false;
        },
        
        /**
         * 搜索区域控制
         * @return {undefined}
         */
        searchAreaControl : function () {

            this.show_btn = !this.show_btn;

            this.$nextTick(function(){

                if( this.show_btn ) {

                    this.$refs.search_box.style.display = 'block';
                    
                    this.$refs.search_input.focus();
    
                }else {

                    this.keyword = '';

                }

            })
            
        },
        
        /**
         * 确认搜索
         * @return {undefined}
         */
        confirmSearch : function () {

            window.location.href = location.origin + '/seo/production?keyword=' + this.keyword

        },

        /**
         *  获取当前页面的url用于激活导航选项
         */
        getCurrentPageUrl: function () {
            this.currentUrl = window.location.href;
        }

    },

    mounted: function () {
        this.getCurrentPageUrl();
    }
}).$mount('#header');


// 返回顶部
new Vue({
    el:'#aside_box',
    data:{
        isShow: false
    },
    mounted:function(){
        var vm = this;

        //事件节流
        window.addEventListener("scroll",debounce( function(event){

            var scrollTop = document.documentElement.scrollTop ||  document.body.scrollTop;
            if( scrollTop <= 20 ){
                vm.isShow = false;
            }else{
                vm.isShow = true;
            }
        } ,200 ));
    },

    methods:{
        backTop:function(){
            document.body.scrollTop = 0;
        },
        service:function(){
            //alert("ke fu")
        }
    }
});

